package com.kerwin.permission;

import com.kerwin.entity.returnjson.AxiosResultGenerics;
import com.kerwin.entity.returnjson.E;
import com.kerwin.entity.returnjson.TableDate;
import com.kerwin.menumgt.MenuService;
import com.kerwin.permmgt.PermService;
import com.kerwin.permmgt.entity.AddPerm;
import com.kerwin.permmgt.entity.Permissions;
import com.kerwin.permmgt.entity.TreePermDetail;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/perm")
public class PermHandler {

@Resource
PermService permService;

    @PostMapping( value = "add")
    public void getUserList(@RequestBody AddPerm addPerm){
//        System.out.println("触发方");
//        System.out.println(form.toString());
        permService.addPerm(addPerm);

    }



    @GetMapping("{id}")
    public void getUserList(@PathVariable String id){
        System.out.println(id);


    }

    @Resource
    MenuService menuService;
    @GetMapping("permList")
    /*把权限列表需要的权限名称和权限id :key传过去*/
    public AxiosResultGenerics<TableDate> getPermList(){
        Map<String, String> permMap = menuService.menuDetails();
        ArrayList<String> permString = new ArrayList<>(permMap.keySet());
        ArrayList<String> permKey = new ArrayList<>(permMap.values());

        return AxiosResultGenerics.SUC(permString,permKey);
    }

    /*返回所有权限数据到前台*/
    /*用树状结构返回前台*/
    @GetMapping("/query/permList")
    public AxiosResultGenerics<TableDate> queryPerm(){
        ArrayList<TreePermDetail> treePermDetails = permService.treePerm();
        return AxiosResultGenerics.SUC(E.SUC,treePermDetails);
        /*我要返回给前台的是菜单数据*/
    }

    /*角色添加用的获取权限名字*/
    @GetMapping("/query/permName")
    public AxiosResultGenerics<TableDate> queryPermName(){
        List<Permissions> permName = permService.getPermName();
        return AxiosResultGenerics.SUC(E.SUC,permName);
        /*我要返回给前台的是菜单数据*/
    }


}
